<?php
class My_UserinfoController extends MM_Controller_My_Action
{	
	/**
	 * 
	 * @var Mediad2_Model_User
	 */
	private $user_model;
	public function indexAction(){
		$this->helper->setPageView($this->pageview, WEB_TITLE, "userinfo", null);
	}
	
	public function updateAction(){
		//更新个人信息
		$oldpwd = $this->httpdata['key1'];
		$newpwd = $this->httpdata['key2'];
		$nickname = $this->httpdata['nickname'];
		$mobile = $this->httpdata['mobile'];
		$qq = $this->httpdata['qq'];
		
		if ( ($this->uid<1) ) {
			$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: uid');
		} else {
			$user = new Mediad2_Service_Admin_User();
			$result = $user->find($this->uid);			
			$this->result = $result;
			
			if($result->getCode()){
			
				$this->user_model = $result->getData();
				if($oldpwd && $newpwd){//更改密码
					if(md5($oldpwd)==$this->user_model->getPwd()){
						$this->user_model->setPwd(md5($newpwd));
						$this->result = $user->update($this->user_model);
					}else{
						$this->result = $this->returnResult(0,"旧密码有误");
					}
				}
				
				if($nickname || $mobile || $qq){//更改个人信息
					if($nickname)
						$this->user_model->setNickname($nickname);
					if($mobile)
						$this->user_model->setMobile($mobile);
					if($qq)
						$this->user_model->setQq($qq);
					$this->result = $user->update($this->user_model);
				}
			}
		}
		echo $this->encodeResult($this->result);
		
	}
}